package com.sys.server.modules.controller;

import com.sys.server.common.annotation.Authentication;
import com.sys.server.common.model.R;
import com.sys.server.modules.controller.dto.CommentDto;
import com.sys.server.modules.controller.dto.IssueDto;
import com.sys.server.modules.service.IssueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Authentication
@Api(tags = "讨论区模块")
public class IssueController {

    @Autowired
    private IssueService issueService;

    @RequestMapping(value = "/createIssue", method = RequestMethod.POST)
    @ApiOperation(value = "讨论区模块--发起讨论")
    public R createIssue(@RequestBody IssueDto issueDto) {
        return issueService.createIssue(issueDto);
    }

    @RequestMapping(value = "/getIssueList", method = RequestMethod.GET)
    @ApiOperation(value = "讨论区模块--分页获取问题列表")
    public R getIssueList(@RequestParam Long pagenum,
                          @RequestParam Long pagesize) {
        return issueService.getIssueList(pagenum, pagesize);
    }

    @RequestMapping(value = "/createFirstComment", method = RequestMethod.POST)
    @ApiOperation(value = "讨论区模块--创建一级回复")
    public R createFirstComment(@RequestBody CommentDto commentDto) {
        return issueService.createFirstComment(commentDto);
    }

    @RequestMapping(value = "/createSecondComment", method = RequestMethod.POST)
    @ApiOperation(value = "讨论区模块--创建二级回复")
    public R createSecondComment(@RequestBody CommentDto commentDto) {
        return issueService.createSecondComment(commentDto);
    }

    @RequestMapping(value = "/getComment", method = RequestMethod.GET)
    @ApiOperation(value = "讨论区模块--查询评论列表")
    public R getComment(@RequestParam Long postid) {
        return issueService.getComment(postid);
    }

}
